#include"HiKernel/HiFramework.h"
#include"HiModules/mHiInterpolator/HiInterpolator.h"

enum ANIMATION
{
	MSG_ANIMATION1,
	MSG_ANIMATION2,	
	MSG_ANIMATION3,	
	MSG_ANIMATION4,	
	MSG_ANIMATION5,	
	MSG_MOTIONBLEND,
	MSG_MOTIONBLENDC,
	MSG_ANIMATIONMOVE_LEFT,
	MSG_ANIMATIONMOVE_RIGHT,
	MSG_NORMAL,
	MSG_CAMERAFOLLOWINGREMOVE,
	MSG_CAMERAFOLLOWINGADD,
	MSG_SUSPENDTEST,
};

mHiInterpolator::mHiInterpolator(HiXmlNode* xml)
{
	m_vVec3f = NULL;
	m_vVec3f = new HiSFVec3f(this, 3, "xyz");
	m_vTrans = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
}

mHiInterpolator::~mHiInterpolator()
{
}

void mHiInterpolator::PostConfig()
{
}

int mHiInterpolator::SetXmlAttrs(HiXmlNode* xml)
{
	return 1;
}

void mHiInterpolator::Update()
{
	
	static long LastTime = timeGetTime();
	static int temp = 0;
	static bool bTemp = false;

	if(GetAsyncKeyState('W'))
		m_vTrans.y +=1.0f;
	else if(GetAsyncKeyState('S'))
		m_vTrans.y -=1.0f;
	else if(GetAsyncKeyState('A'))
	{
		m_vTrans.x +=1.0f;
		Dispatch->DispatchMessage(0, this->GetName(), "caltest", MSG_ANIMATIONMOVE_LEFT, 0);
	}
	else if(GetAsyncKeyState('D'))
	{
		m_vTrans.x -=1.0f;
		Dispatch->DispatchMessage(0, this->GetName(), "caltest", MSG_ANIMATIONMOVE_RIGHT, 0);
	}
	else
		Dispatch->DispatchMessage(0, this->GetName(), "caltest", MSG_NORMAL, 0);
	if(::GetAsyncKeyState('C'))
		Dispatch->DispatchMessage(0, this->GetName(), "cam", MSG_CAMERAFOLLOWINGREMOVE, 0);
	if(::GetAsyncKeyState('V'))
		Dispatch->DispatchMessage(0, this->GetName(), "cam", MSG_CAMERAFOLLOWINGADD, 0);
	if(::GetAsyncKeyState('B'))
		m_bActive = false;

	if(::GetAsyncKeyState('Z'))
		Dispatch->DispatchMessage(0, this->GetName(), "caltest", MSG_SUSPENDTEST, 0);

	
	if(::GetAsyncKeyState('Q'))
		Dispatch->DispatchMessage(0, this->GetName(), "ModuleManager", MSG_SUSPENDTEST, 0);


	m_vVec3f->Set(m_vTrans);

	Realize();
}

void mHiInterpolator::Realize()
{
	this->SendEvent(m_vVec3f);
}



extern "C" HI_DLLEXPORT
mHiInterpolator* HiLoadModule_mHiInterpolator(HiXmlNode* xml)
{
	mHiInterpolator *m= new mHiInterpolator(xml);
	return m;
}
